<template>
  <el-dialog :append-to-body="true" :close-on-click-modal="false" :modal="false" :title="'审计问题'" :visible.sync="visible" custom-class="ledger" fullscreen top="5vh" width="1200px" :before-close="cancelDialog" >
    <div class="colums">
      <div class="colums_left">
        <div class="colums_left_middle">
           <div class="middleForm ledger" style="overflow-x: hidden">
            <el-form ref="dataForm" :model="problemForm" class="el-dialog__body" label-width="100px" style="margin-bottom: 10px;">
<!--              <el-row>-->
<!--                <el-col :span="8">-->
<!--                  <el-form-item label-width="120px" label="记录人:">-->
<!--                    {{problemForm.recordName}}-->
<!--                  </el-form-item>-->
<!--                </el-col>-->
<!--                <el-col :span="8">-->
<!--                  <el-form-item label-width="120px" label="记录日期:">-->
<!--                    <el-date-picker v-model="problemForm.recordDate" class="datePicker" format="yyyy-MM-dd" placeholder="选择日期" placement="bottom-start" type="date" value-format="yyyy-MM-dd" disabled></el-date-picker>-->
<!--                  </el-form-item>-->
<!--                </el-col>-->
<!--                <el-col :span="6">-->
<!--                  <el-form-item label="问题编号:">-->
<!--                    {{ problemForm.findNo }}-->
<!--                  </el-form-item>-->
<!--                </el-col>-->
<!--              </el-row>-->
              <div class="title">项目信息</div>
              <el-row>
                <el-col :span="8">
                  <el-form-item label-width="120px" label="项目编号:">
                    {{ problemForm.projectId }}
                  </el-form-item>
                </el-col>
                <el-col :span="16">
                  <el-form-item label-width="120px" label="审计项目名称:">
                    {{ problemForm.projectName }}
                  </el-form-item>
                </el-col>
              </el-row>
              <div class="title">审计发现</div>
              <el-row>
                <el-col :span="8">
                  <el-form-item label-width="120px" label="问题类型:">
                    <el-select v-model="problemForm.problemType" @change="handleSelect(problemForm.problemType)">
                      <el-option v-for="problemType in problemTypes" :key="problemType.value" :label="problemType.label" :value="problemType.value" ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label-width="120px" label="问题金额类型:" :hidden="isEdit">
                    <el-select v-model="problemForm.problemAmountType" :disabled="isEdit">
                      <el-option v-for="problemAmountType in problemAmountTypes" :key="problemAmountType.value" :label="problemAmountType.label" :value="problemAmountType.value"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="问题金额:" :hidden="isEdit">
                    <el-input-number v-model="problemForm.problemAmount" :disabled="isEdit" v-thousand :min="0" style="width: 200px"></el-input-number>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col>
                  <el-form-item label-width="120px" label="问题标题:">
                    <el-input v-model="problemForm.problemTitle" type="textarea" :autosize="{ minRows: 2}"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col>
                  <el-form-item label-width="120px" label="问题描述:">
                    <el-input v-model="problemForm.problemDesc" type="textarea" :autosize="{ minRows: 2}"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
<!--              <el-row>-->
<!--                <el-col>-->
<!--                  <el-form-item label-width="120px" label="定性及依据:">-->
<!--                    <el-input v-model="problemForm.basisInfo" type="textarea" :autosize="{ minRows: 2}"></el-input>-->
<!--                  </el-form-item>-->
<!--                </el-col>-->
<!--              </el-row>-->
<!--              <el-row>-->
<!--                <el-col>-->
<!--                    <el-form-item label-width="120px" label="审计意见及依据:">-->
<!--                      <el-input v-model="problemForm.opinion" type="textarea" :autosize="{ minRows: 2}"></el-input>-->
<!--                    </el-form-item>-->
<!--                </el-col>-->
<!--              </el-row>-->
              <el-row>
                <el-col>
                  <el-form-item label-width="120px" label="审计意见及建议:">
                    <el-input v-model="problemForm.suggestion" type="textarea" :autosize="{ minRows: 2}"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
<!--              <el-row>-->
<!--                <el-col>-->
<!--                  <el-form-item label-width="120px" label="备注:">-->
<!--                    <el-input v-model="problemForm.remark" type="textarea" :autosize="{ minRows: 2}"></el-input>-->
<!--                  </el-form-item>-->
<!--                </el-col>-->
<!--              </el-row>-->
            </el-form>
           </div>
        </div>
      </div>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button icon="el-icon-close" size="small" @click="cancelDialog">关闭</el-button>
      <el-button icon="el-icon-check" size="small" type="primary" @click="submit">保存</el-button>
    </span>
  </el-dialog>
</template>

<script>
import {mapGetters} from "vuex";
import Tinymce from '@/components/Tinymce';
import {submit,getProblem} from "@/api/adis/execute/discover";
import {getEvidence} from "@/api/adis/execute/evidence";

export default {
  components: {
    Tinymce,
  },
  dictTypes: ['audit_type'],
  computed: {
    ...mapGetters(["permissions","userInfo"])
  },
  data() {
    return {
      visible: false,
      canSubmit: false,
      isEdit: false,
      form: {},
      problemForm: {
        recordDate: new Date().toISOString(),
      },
      problemTypes:[
        {value:0,label:'经济类问题'},
        {value:1,label:'非经济类问题'}
      ],
      problemAmountTypes:[
        {value:0,label:'绩效性问题金额'},
        {value:1,label:'合规类问题金额'}],
      pointForm: {},
      item: {},
    }
  },
  methods: {
    handleSelect(problemType){
      this.isEdit = problemType === 1;
      // this.problemForm.problemAmountType = '';
      this.$set(this.problemForm, "problemAmountType", '');
      this.problemForm.problemAmount = '';
    },
    init(row) {
      this.canSubmit = true;
      this.form.recordName = this.userInfo.username;
      this.form.evidenceId = row.evidenceId;
      this.form.recordDate = new Date().toISOString();
      this.form.archiveYear = new Date().toISOString().split('-')[0];
      this.$nextTick(() => {
        if (row.problemId) {
          getProblem(row.problemId).then(response => {
            this.problemForm = response.data.data;
            this.isEdit = this.problemForm.problemType === 1;
            this.visible = true;
          })
        }else if(row.evidenceId){
          getEvidence(row.evidenceId).then((res)=>{
            this.evidenceForm = res.data.data;
            let newObject = Object.assign({},this.evidenceForm, this.form);
            this.$set(this, "problemForm", newObject);
            console.log(this.form);
            console.log(this.problemForm);
            // this.problemForm.auditArrayTime = [this.evidenceForm.auditStartDate, this.evidenceForm.auditEndDate];
            this.problemForm.problemDesc = this.evidenceForm.auditMatterAbstract+'；'+this.evidenceForm.lawContent;
            this.visible = true;
          })
        }
      })
    },
    // 表单提交
    submit() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          // this.fileList && this.fileList.map((file) => {
          //   this.form.fileUrl = file.response ? file.response.data.url : file.url
          // });
          this.loading = true;
          submit(this.problemForm).then(() => {
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.cancelDialog();
          }, () => {
            this.loading = false;
          });
        } else {
          return false;
        }
      });
    },
    //重置表单
    cancelDialog() {
      this.visible = false;
      this.$emit('cancelDialog', {})
      this.$refs['dataForm'].resetFields()
    },
  }
}
</script>
